package com.xiaoshuidi.cloud.module.report.constant;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 预定状态
 *
 */
@Getter
@AllArgsConstructor
public enum RoomHouseReserveStatus {

    TO_BE_PAID("1", "待支付"),
    RESERVED("2", "已预定"),
    CANCELED("3", "已取消"),
    SINGED("4", "已签约");


    private String code;
    private String name;

    public static String getCodeByName(String name) {
        if (StrUtil.isEmpty(name)) {
            return null;
        }
        Optional<RoomHouseReserveStatus> find = Arrays.stream(RoomHouseReserveStatus.values()).filter(s -> s.getName().equals(name)).findFirst();
        if (find.isPresent()) {
            return find.get().getCode();
        }
        return null;
    }

    public static String getNameByCode(String code) {
        if (StrUtil.isEmpty(code)) {
            return null;
        }
        Optional<RoomHouseReserveStatus> find = Arrays.stream(RoomHouseReserveStatus.values()).filter(s -> s.getCode().equals(code)).findFirst();
        if (find.isPresent()) {
            return find.get().getName();
        }
        return null;
    }

    public static Boolean containCode(String code){
        for (RoomHouseReserveStatus reserveStatus : RoomHouseReserveStatus.values()) {
            if(reserveStatus.code.equals(code)){
                return true;
            }
        }
        return false;
    }

}
